package com.seeyon.apps.kkSample.utils;

import com.seeyon.ctp.common.SystemEnvironment;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Properties;
import java.util.regex.Matcher;

public class PropertiesConfigUtil {
    private static Log log = LogFactory.getLog(PropertiesConfigUtil.class);


    //文件存放路径重新编辑
    public static final DateFormat yyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
    //文件存放路径重新编辑
    public static final DateFormat yyyyMMddhhmmss = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    //年度
    public static final DateFormat yearFormat = new SimpleDateFormat("yyyy");


    // 获取配置文件的信息
    public static Properties getPropertiesDingshi() {
        Properties properties = new Properties();
        String filepath = "config/AliTripSyn.properties";
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        InputStream inputStream = classloader.getResourceAsStream(filepath);
        try {
            InputStreamReader reader = new InputStreamReader(inputStream, "UTF-8");
            properties.load(reader);
            return properties;
        } catch (Exception e) {
            log.info("客开--企微打开数据同步-读取配置文件异常" + e.getMessage(), e);
        }
        return null;
    }

    //修改配置文件信息
    public static void getProperties(Properties properties) {
        String filepath = SystemEnvironment.getApplicationFolder().split("ApacheJetspeed")[0]
                .replaceAll("\\\\", Matcher.quoteReplacement(File.separator)) +"ApacheJetspeed/webapps/seeyon/WEB-INF/classes/config/AliTripSyn.properties";
        try {
            OutputStream os = new FileOutputStream(filepath);
            properties.store(os, null);
        } catch (Exception e) {
            log.info("客开--企微打开数据同步-修改配置文件异常" + e.getMessage(), e);
        }
    }



    // 获取配置文件的信息
    public static Properties getPropertiesDingshidzd() {
        Properties properties = new Properties();
        String filepath = "config/AliTripSyndzd.properties";
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        InputStream inputStream = classloader.getResourceAsStream(filepath);
        try {
            InputStreamReader reader = new InputStreamReader(inputStream, "UTF-8");
            properties.load(reader);
            return properties;
        } catch (Exception e) {
            log.info("客开--阿里对账单同步-读取配置文件异常" + e.getMessage(), e);
        }
        return null;
    }
    public static Properties getPropertiesXCdzd() {
        Properties properties = new Properties();
        String filepath = "config/XCSyndzd.properties";
        ClassLoader classloader = Thread.currentThread().getContextClassLoader();
        InputStream inputStream = classloader.getResourceAsStream(filepath);
        try {
            InputStreamReader reader = new InputStreamReader(inputStream, "UTF-8");
            properties.load(reader);
            return properties;
        } catch (Exception e) {
            log.info("客开--携程对账单同步-读取配置文件异常" + e.getMessage(), e);
        }
        return null;
    }

    //修改配置文件信息
    public static void getPropertiesdzd(Properties properties) {
        String filepath = SystemEnvironment.getApplicationFolder().split("ApacheJetspeed")[0]
                .replaceAll("\\\\", Matcher.quoteReplacement(File.separator)) +"ApacheJetspeed/webapps/seeyon/WEB-INF/classes/config/AliTripSyndzd.properties";
        try {
            OutputStream os = new FileOutputStream(filepath);
            properties.store(os, null);
        } catch (Exception e) {
            log.info("客开--企微打开数据同步-修改配置文件异常" + e.getMessage(), e);
        }
    }




}
